﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace MODULE_QUANTRIHETHONG
{
    public class cls_quantrihethong
    {
        public System.Windows.Forms.Form parent;
        public static  string tendangnhap;//Bien toan cuc lam session luu ten dang nhap.
       // int x, y;//vi tri trung tam man hinh;
        frm_startup frmstartup=new frm_startup();
        frm_doimatkhau frmdoimatkhau = new frm_doimatkhau();
        frm_login frmlogin = new frm_login();
        frm_thamso frmthamso = new frm_thamso();
        frm_main frmmain=new frm_main();
      
        public static hethongDataContext getcontext()
        {
            return new hethongDataContext(getconnectstring());
        }
    
        private string matkhau;
        public string _password
        {
            get { return matkhau; }
            set { matkhau = value; }
        }
        public string _tendangnhap
        {
            get { return tendangnhap;
            }
            set 
            {
                tendangnhap = value;
            }
        }
        
        private bool bdangnhap;
        public bool _bdangnhap
        {
            get { return bdangnhap; }
            set { bdangnhap = value; }
        }
        private bool bexit;
        public bool _bexit
        {
            get { return bexit; }
            set { bexit = value; }
        }
       
        
        public void ShowForm(string formname)
        {
            
            switch (formname)
            {
                case "frm_startup":
                    frmstartup= new frm_startup();
                    frmstartup.Show();
                    break;
                case "frm_doimatkhau":
                    frmdoimatkhau = new frm_doimatkhau();
                    frmdoimatkhau._username = this._tendangnhap;
                    frmdoimatkhau.MdiParent = parent;
                    frmdoimatkhau.Show();
                    break;
                case "frm_main":
                    frmmain = new frm_main();
                    frmmain.Show();
                    break;
                case "frm_login":
                   frmlogin=new frm_login();
                    frmlogin.ShowDialog();
                    tendangnhap = frmlogin._susername;
                    bdangnhap = frmlogin.flag;
                    bexit = frmlogin.exit;
                    break;
                case "frm_thamso":
                    frmthamso = new frm_thamso();
                    frmthamso.MdiParent = parent;
                    frmthamso.Show();

                    break;
                case "exit":
                    System.Windows.Forms.Application.Exit();
                    break;
                case"relogin":
                    //FormCollection collection = System.Windows.Forms.Application.OpenForms;
                    //for (int i = 0; i < collection.Count; i++)
                    //{
                    //    System.Windows.Forms.MessageBox.Show(collection[i].Name);
                    //}
                    //Application.Run(frmstartup);
                    //frmmain.Close();
                    //frmstartup.Show();
                    //frmlogin.ShowDialog();
                    //tendangnhap = frmlogin._susername;
                    //bdangnhap = frmlogin.flag;
                    //bexit = frmlogin.exit;

                    break;
            }
        }

        public static string getconnectstring()
        {
            string kq = "";
            XmlDocument MyDoc = new XmlDocument();

            MyDoc.Load("extension\\extension.xml");
            XmlNode root = (XmlNode)MyDoc.DocumentElement;

            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                XmlNode element = (XmlNode)root.ChildNodes[i];
                if (element.Name == "connection")
                {
                    kq = element.Attributes["connectionString"].Value.ToString();
                }
            }
            return kq;

        }

    }
}
